/* ---------------------------------Marlin Toolkit-----------------------------*
Authors : Daniel Randle, Alex Bourne
Date Created : Mar 25 2013

File:
	inputmapping.h

Description:
	This file contains the declaration for the InputMapping class along with any
	helper functions associated with the class
*-----------------------------------------------------------------------------*/
#ifndef INPUTMAPPING_H
#define INPUTMAPPING_H

#include <qevent.h>
#include <qvector.h>
#include <nsmath3d.h>
#include <global.h>


class NSEngine;
class NSObject;
class NSObjectReference;
class Debug;

namespace ToolkitGui
{
	class MapWindow;
}

class InputMapping
{
public:
	InputMapping(NSEngine * eng, ToolkitGui::MapWindow * mapWindow);

	enum Inversion {Inverted=-1,NotInverted=1};

	enum Function {AngleMouse, MovementMouse, 
					 ZoomIn, ZoomOut,
					 ObjectMouseZ,ObjectRotateMouseX,
					 ObjectRotateMouseY,ObjectRotateMouseZ,
					 ObjectMoveXPlus, ObjectMoveXMinus, 
					 ObjectMoveYPLus,ObjectMoveYMinus,
					 ObjectMoveZPlus,ObjectMoveZMinus,
					 ObjectRotateXPlus,ObjectRotateXMinus,
					 ObjectRotateYPlus,ObjectRotateYMinus,
					 ObjectRotateZPlus,ObjectRotateZMinus,
					 ObjectSnapToGrid, CamInvertX, CamInvertY,
					 CamForward,CamReverse,CamStrafeLeft,
					 CamStrafeRight,CamElevate,CamDrop,
					 Delete, BuildMode, MultSelActivator,
					 PaintSelection,
					 ToggleView,ToggleCamera,ToggleRotate};
	
	void setFunctionKey(Qt::Key key, Function func);
	bool checkWrappedMouse(NSVec2Df & pos);
	void moveObject(bool xDir, bool yDir, bool zDir,int direction);
	void rotateObject(bool xAxis, bool yAxis, bool zAxis, int direction);
	void selAtCurrentMousePos();
	void selAtPos(const NSVec2Df & mPosition);
	void setSelection(NSObjectReference* item);
	void deselect();
	void deleteSelectedRefs();
	void setEngine(NSEngine * eng);
	void enterBuildMode(bool enter);
	void setMouseSelObjectCenter();
	void setMouseAtObject(const NSVec3Df & objPos);
	void setMouseOffset();


	void onMouseMovement(QMouseEvent *mevent);
	void onMousePress(QMouseEvent *mevent);
	void onMouseRelease(QMouseEvent *mevent);
	bool onKeyPress(QKeyEvent * kEvent);
	bool onKeyRelease(QKeyEvent * kEvent);
	void onMouseWheel(QWheelEvent * wEvent);

	void postGUIUpdate();

	#ifdef DEBUG
	void setDebug(Debug * dbg);
	#endif

private:
	QVector<int> keyMap;
	bool middleMouseHeld;
	bool rightMouseHeld;
	bool leftMouseHeld;
	bool angleMouseHeld;
	bool movementMouseHeld;
	bool objectZHeld;
	bool objectRotateXHeld;
	bool objectRotateYHeld;
	bool objectRotateZHeld;
	bool snapToGrid;
	bool selectionMode;
	bool addToSelection;
	bool paintingSelection;
	bool mouseMovedWithButton;

	#ifdef DEBUG
	Debug * d;
	#endif

	ToolkitGui::MapWindow * mapWin;

	Inversion invertY;
	Inversion invertX;

	NSVec2Df mousePos;
	NSVec2Df offset;

	NSEngine * engine;

};


#endif